<template>
  <div class="student">
    <h1>{{ msg }}</h1>
    <h2>学生姓名：{{ name }}</h2>
    <h2>学生性别：{{ sex }}</h2>
    <h2>学生年龄：{{ age + 1 }}</h2>
  </div>
</template>

<script>
export default {
  name: "StudentlInfo",
  data() {
    return {
      msg: "毕业于临沂大学的学生",
      name: "大志强",
      sex: "男",
      age: 18,
    };
  },
  methods: {
    transMsg(data) {
      console.log("我是student组件，传递消息", data);
    },
  },
  mounted() {
    // this.$bus.$on("sendMsg",this.transMsg)
    this.$bus.$on("sendMsg", (data) => {
      console.log("我是student组件的绑定函数，传递的消息", data);
    });
  },
  beforeDestroy(){
    this.$bus.$off("sendMsg");
  }
};
</script>
<style scoped>
.student {
  background-color: aqua;
}
</style>

